package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.base.BaseObjectModel;
import com.magic.gre.mvp.contract.SetModifyPwsdContract;
import com.magic.gre.mvp.model.SetModifyPwsdModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;

/**
 * Author: Lmoumou
 * Date: 2019-01-11 10:03
 * 文件名: SetModifyPwsdPrersenterImpl
 * 描述:
 */
public class SetModifyPwsdPrersenterImpl extends BasePresenterImpl<SetModifyPwsdContract.View, SetModifyPwsdContract.Model>
        implements SetModifyPwsdContract.Presenter {

    public SetModifyPwsdPrersenterImpl(SetModifyPwsdContract.View view) {
        super(view);
    }

    @Override
    protected SetModifyPwsdContract.Model creatModel() {
        return new SetModifyPwsdModelImpl();
    }

    @Override
    public void pSmsCode(String phone,int type) {
        mModel.mSmsCode(new CommonObserver<BaseObjectModel<String>>(new TypeToken<BaseObjectModel<String>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<String> stringBaseObjectModel) {
                mView.vSmsCode(stringBaseObjectModel.body);

            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
                mView.hideLoadDialog();
            }
        },phone,type);
    }

    @Override
    public void pModify(String phone,String newPwd) {
        mModel.mModify(new CommonObserver<BaseObjectModel>(new TypeToken<BaseObjectModel>(){}.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel baseObjectModel) {
                mView.vModify();
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, phone,newPwd);
    }
}
